home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- import os.path as os
- import math
- import wx
- from gui import skin
- from gui.skin.skinobjects import Margins
- from gui.toolbox.imagefx import wxbitmap_in_square
- from gui.toolbox import Monitor, AutoDC
- from util import do
- from wx import TextCtrl
- UberEmotiBase = wx.PopupTransientWindow
-
- class UberEmotiBox(UberEmotiBase):
-
- def __init__(self, parent, emoticons, textctrl):
- UberEmotiBase.__init__(self, parent, style = wx.NO_BORDER)
- self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
- self.SetExtraStyle(wx.WS_EX_PROCESS_IDLE)
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.UpdateSkin()
- self.textctrl = textctrl
- (self.pemoticons, pwidth, pheight) = self.Arrange(self, emoticons)
- self.lesssize = (pwidth, pheight)
- self.SetSize(self.lesssize)
-
-
- def UpdateSkin(self):
- skin_elements = [
- ('padding', 'padding', (lambda : wx.Point(3, 3))),
- ('margins', 'margins', skin.ZeroMargins),
- ('esize', 'emoticonsize', 19),
- ('espace', 'emoticonspace', 23),
- ('bg', 'backgrounds.window', None)]
- for attr, skinattr, default in skin_elements:
- setattr(self, attr, skin.get('emotibox.' + skinattr, default))
-
-
-
- def Arrange(self, parent, emots):
- width = round(math.sqrt(len(emots)))
- if width < 4:
- width = 4
-
- if width > 7:
- width = 7
-
- size = self.espace
- padding = self.padding
- margins = self.margins
- cx = padding.x + margins.left
- cy = padding.y + margins.top
- emoticons = []
- count = 0
- for emot in emots:
- emoticons.append(Emoticon(parent, emot, (cx, cy)))
- cx += size + padding.x
- count += 1
- if count == width:
- cx = padding.x
- cy += size + padding.y
- count = 0
- continue
-
- if cx != padding.x:
- cy += size + padding.y
-
- across = width * (size + padding.x) + padding.x + margins.x
- cy += margins.bottom
- if cy < across:
- cy = across
-
- return (emoticons, across, cy)
-
-
- def OnPaint(self, event):
- dc = AutoDC(self)
- self.bg.Draw(dc, self.ClientRect)
-
-
- def Display(self, rect):
- pos = rect.BottomLeft
- newrect = wx.RectPS(pos, self.Size)
- screenrect = Monitor.GetFromRect(newrect).ClientArea
- if newrect.bottom > screenrect.bottom:
- pos.y -= rect.height + self.Size.height
-
- if newrect.right > screenrect.right:
- pos.x += rect.width - self.Size.width
-
- self.SetPosition(pos)
- self.Popup()
-
-
-
- class Emoticon(wx.Window):
-
- def __init__(self, parent, emot, pos):
- wx.Window.__init__(self, parent, pos = pos)
- self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
- events = [
- (wx.EVT_PAINT, self.OnPaint),
- (wx.EVT_ENTER_WINDOW, self.OnMouseInOrOut),
- (wx.EVT_LEAVE_WINDOW, self.OnMouseInOrOut),
- (wx.EVT_LEFT_UP, self.OnLeftUp)]
- for evt, meth in events:
- self.Bind(evt, meth)
-
- (imgpath, self.keys) = emot
- self.SetToolTipString(' '.join(self.keys))
- self.emote = None
-
- try:
- bitmap = wx.Bitmap(imgpath)
- if bitmap.Ok():
- self.emote = bitmap
- except Exception:
- print_exc = print_exc
- import traceback
- print_exc()
-
- self.UpdateSkin()
-
-
- def UpdateSkin(self):
- size = skin.get('emotibox.emoticonspace', 24)
- self.Size = wx.Size(size, size)
- esize = skin.get('emotibox.maxemoticonsize', 16)
- self.normalbg = skin.get('emotibox.backgrounds.emoticon', None)
- self.hoverbg = skin.get('emotibox.backgrounds.hover', None)
- emote = self.emote
- if emote is not None:
- self.bitmap = emote.ResizedSmaller(esize)
- else:
- self.bitmap = None
-
-
- def OnPaint(self, event):
- dc = wx.BufferedPaintDC(self)
- rect = wx.RectS(self.Size)
- if wx.FindWindowAtPointer() is self:
- self.hoverbg.Draw(dc, rect)
- else:
- self.normalbg.Draw(dc, rect)
- (W, H) = self.GetSize()
- (w, h) = self.bitmap.GetSize()
- if self.bitmap is not None:
- dc.DrawBitmap(self.bitmap, W / 2 - w / 2, H / 2 - h / 2, True)
-
-
-
- def OnMouseInOrOut(self, event):
- event.Skip()
- self.Refresh()
-
-
- def OnLeftUp(self, event):
- textctrl = self.Parent.textctrl
- ip = textctrl.InsertionPoint
- if ip != 0 and textctrl.Value[ip - 1] and textctrl.Value[ip - 1] != ' ':
- space = textctrl.WriteText(' ')
- else:
- space = ''
- textctrl.WriteText(''.join([
- space,
- self.keys[0],
- ' ']))
- self.Parent.Dismiss()
- self.Parent.textctrl.SetFocus()
-
-
-